package jm.data.structure.leet_code;

import java.util.List;

/**
 * @Description https://leetcode-cn.com/problems/linked-list-cycle/
 * @date 2022/4/6 9:02
 */
public class _141环形链表 {
    public static void main(String[] args) {

    }

    public static boolean hasCycle(ListNode head) {
        if (head == null || head.next == null){
            return false;
        }
        ListNode slow = head;
        ListNode fast = head.next;
        while (fast != null && fast.next != null){
            if (slow == fast){
                return true;
            }
            fast = fast.next.next;
            slow = slow.next;
        }
        return false;
    }

    static class ListNode{
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}
